<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <p>生命周期钩子函数</p>
    <button @click="detroy">销毁</button>
    <input type="text" v-model="name">
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        name: 'Tom'
      },
      beforeCreate() {
        console.log('======');
        console.log('1.beforeCreate-实例创建前');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      created() {
        console.log('======');
        console.log('2.created-实例创建后');
        console.log(this.$data);
        this.sayHi()
        console.log(this.$el);
        console.log('======');
      },
      beforeMount() {
        console.log('======');
        console.log('3.beforeMount-渲染前');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      mounted() {
        console.log('======');
        console.log('4.mounted-渲染后');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      beforeUpdate() {
        console.log('======');
        console.log('5.beforeUpdate-更新前');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      updated() {
        console.log('======');
        console.log('6.updated-更新后');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      beforeDestroy() {
        console.log('======');
        console.log('7.beforeDestroy-vue实例销毁前');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      destroyed() {
        console.log('======');
        console.log('8.destroyed-vue实例销毁后');
        console.log(this.$data);
        console.log(this.$el);
        console.log('======');
      },
      methods: {
        detroy() {
          // 销毁实例
          this.$destroy()
        },
        sayHi() {
          console.log('hi');
        }
      },
    })
  </script>
</body>
</html>